#ifndef IMAGEUTILS_H_
#define IMAGEUTILS_H_


#include <cxcore.h>
#include <cv.h>


#include "Pixel.h"
//#include "Blob.h"


class ImageUtils
{
private:
	ImageUtils();
	virtual ~ImageUtils();
	
	
public:

	static const int ORDER_BGR = 0x01; 
	static const int ORDER_RGB = 0x02; 
	
	
/*************** METHODS ***************/

public:
	static float fitRange(float value, float low, float high);
	static float maxi(float a, float b, float c=0);
	static float mini(float a, float b, float c=0);

	static void copyRegion(IplImage* src, IplImage* dst, CvPoint start, CvPoint end);
    
    static void removeStrayPixels(IplImage *src, IplImage *dst, int step = 1);
    
    static int getPixelValue(IplImage *image, int x, int y);
    static int getPixelValue(IplImage *image, CvPoint point);
    static int getPixelValue(IplImage *image, int x, int y, int channel);
    static int getPixelValue(IplImage *image, CvPoint point, int channel);
    static Pixel getPixel(IplImage *image, int x, int y, int numChannels = 1);
    static Pixel getPixel(IplImage *image, CvPoint point, int numChannels = 1);
    
    
    static void setPixelValue(IplImage* image, int x, int y, int channel, int value);
    static void setPixelValue(IplImage* image, CvPoint point, int channel, int value);
    static void setPixelValue(IplImage* image, int x, int y, int num_channels, int* value, int order = ORDER_BGR);
    static void setPixelValue(IplImage* image, CvPoint point, int num_channels, int* value, int order = ORDER_BGR);
    static void setPixel(IplImage* image, Pixel pixel);
    
 	static bool isSkinColor(Pixel pixel);
    static bool isSkinColor(int b, int g, int r);
    static bool isSkinColorRGB(int b, int g, int r);
    static bool isSkinColorHSV(int b, int g, int r);
    static bool isSkinColorYCbCr(int b, int g, int r);
    
    static CvScalar getMarkerColor(int index = 0);
    static bool     isMarkerColor(int r, int g, int b);
    
	static void drawArrow(IplImage* image, CvPoint start, CvPoint end, CvScalar color);
    static void drawRect(IplImage* image, CvPoint topLeft, CvPoint bottomRight, CvScalar color, bool filled = false);
    static void drawRect(IplImage* image, CvRect rect, CvScalar color, bool filled = false);
    static void drawBox2D(IplImage* image, CvBox2D box, CvScalar color);
    static void drawBox2DFilled(IplImage* image, CvBox2D box, CvScalar color);
 /*   static void drawContour(IplImage* image, Blob* blob, bool filled = false);
    
    static void    findContour(Blob* blob);
    static CvBox2D findEnclosingEllipse(Blob* blob);*/
    
    
    static void addEllipseEnclosedPixels(IplImage* image, IplImage* src, CvPoint start, CvPoint end, CvBox2D ellipse);
    
    
    static CvScalar getColorDifference(CvScalar colorA, CvScalar colorB);
    
    
    static void createMask(IplImage* image, IplImage* mask); 
    static void copyByMask(IplImage* src, IplImage* dst, IplImage* mask);
    
    static IplImage* getMaskFromCvBox2D(CvBox2D box, int width, int height);
    
    
    static bool overlaps(CvRect a, CvRect b);
    static double getOverlap(CvRect a, CvRect b);
    
    
    /* vom cbr-projekt */
    static IplImage* normalize( float ** data, int sizeX, int sizeY );
    static float** convertImageToResizedGrey( IplImage* img, int newWidth, int newHeight );
    static float** convertIplImageToFloat( IplImage *img );
    static IplImage* getSubImage(IplImage* src, CvPoint start, CvPoint end);
    static IplImage* getSubImageAsGrey(IplImage* src, CvPoint start, CvPoint end);
    
/*************** MEMBERS ***************/
    
protected:

	// const static int MAX_MARKER_COLORS = 63;  Dieser Wert ist Falsch !!!!
	const static int MAX_MARKER_COLORS = 60;
	
	// static CvScalar markerColors[];  TODO - Dies funktioniert nicht mit meiner Version !!!
	
	static bool initialized;
	
	
};

#endif /*UTILS_H_*/
 
